﻿using _1_Interfaces.Interfaces.Cjw;
using _1_Interfaces.Models.Dtos.Cjw;
using _1_Interfaces.Models.Tables.Cjw;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace _3_Controllers.Controllers.Cjw
{
    /// <summary>
    /// 就诊人表服务
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class CjwPatientController : ControllerBase
    {
        private IPatientService _patientService;
        public CjwPatientController(IPatientService patientService)
        {
            _patientService = patientService;
        }

        /// <summary>
        /// 查询用户列表
        /// </summary>
        /// <param name="patientName">患者姓名</param>
        /// <param name="phoneNumber">手机号码</param>
        /// <param name="idNumber">身份证</param>
        /// <param name="sex">null全部 1男 0女</param>
        /// <param name="pageIndex">第几页</param>
        /// <param name="pageSize">一页几条</param>
        /// <returns></returns>
        [HttpGet]
        public PatientListDto GetPatientList(string patientName, string phoneNumber, string idNumber, string sex, int pageIndex, int pageSize)
        {
            return _patientService.GetPatientList(patientName, phoneNumber, idNumber, sex, pageIndex, pageSize);
        }

        /// <summary>
        /// 新增用户
        /// </summary>
        /// <param name="patientList">id不用管它</param>
        /// <returns></returns>
        [HttpPost]
        public bool InsertPatient(PatientList patientList)
        {
            return _patientService.InsertPatient(patientList);
        }

        /// <summary>
        /// 添加前台看病记录
        /// </summary>
        /// <param name="patientRecordList">除了病人id一定要给，其他的无所谓</param>
        /// <returns></returns>
        [HttpPost]
        public bool InsertPatientRecord(PatientRecordList patientRecordList)
        {
            return _patientService.InsertPatientRecord(patientRecordList);
        }

        /// <summary>
        /// 获取等待被看病人的列表
        /// state=2
        /// </summary>
        /// <param name="docId">医生id</param>
        /// <param name="pageIndex">第几页</param>
        /// <param name="pageSize">一页几条</param>
        /// <returns></returns>
        [HttpGet]
        public GetPatientRecordDto GetAppList(string docId, int pageIndex, int pageSize)
        {
            return _patientService.GetPatientRecordList(-1,null, null, null, null, pageIndex, pageSize, 2);
        }

        /// <summary>
        /// 添加医生看病记录
        /// </summary>
        /// <param name="insertDocRecordDto"></param>
        /// <returns></returns>
        [HttpPost]
        public bool InsertDocRecord(InsertDocRecordDto insertDocRecordDto)
        {
            return _patientService.InsertDocRecord(insertDocRecordDto);
        }

        /// <summary>
        /// 获取等待入院的列表
        /// state=4
        /// </summary>
        /// <param name="pageIndex">第几页</param>
        /// <param name="pageSize">一页几条</param>
        /// <returns></returns>
        [HttpGet]
        public GetPatientRecordDto GetInHospitalList(int pageIndex, int pageSize)
        {
            return _patientService.GetPatientRecordList(-1,null, null, null, null, pageIndex, pageSize, 4);
        }

        /// <summary>
        /// 根据科室id获取科室下面的空闲中的病床的列表(病床状态是1)
        /// </summary>
        /// <param name="departmentId">科室id</param>
        /// <returns></returns>
        [HttpPost]
        public List<SickBedList> GetSickBedsByDepartmentId(int departmentId)
        {
            return _patientService.GetSickBedsByDepartmentId(departmentId);
        }

        /// <summary>
        /// 分配病床
        /// </summary>
        /// <param name="inSickBedDto"></param>
        /// <returns></returns>
        [HttpPost]
        public bool InSickBed(InSickBedDto inSickBedDto)
        {
            return _patientService.InSickBed(inSickBedDto);
        }

        /// <summary>
        /// 获取看病记录
        /// </summary>
        /// <param name="departmentId">科室id</param>
        /// <param name="patientName">患者姓名</param>
        /// <param name="phoneNumber">手机号码</param>
        /// <param name="idNumber">身份证</param>
        /// <param name="sex">1男 0女</param>
        /// <param name="pageIndex">第几页</param>
        /// <param name="pageSize">一页几条</param>
        /// <param name="state">状态 1前台诊断中 2等待医生诊断 3医生诊断中 4办理住院中 5住院中 6已出院</param>
        /// <returns></returns>
        [HttpGet]
        public GetPatientRecordDto GetPatientRecordList(int departmentId, string patientName, string phoneNumber, string idNumber, string sex, int pageIndex, int pageSize, int state)
        {
            return _patientService.GetPatientRecordList(departmentId, patientName, phoneNumber, idNumber, sex, pageIndex, pageSize, 5);
        }

        /// <summary>
        /// 出院
        /// </summary>
        /// <param name="leaveHopitalDto"></param>
        /// <returns></returns>
        [HttpPost]
        public bool LeaveHopital(LeaveHopitalDto leaveHopitalDto)
        {
            return _patientService.LeaveHopital(leaveHopitalDto);
        }

        /// <summary>
        /// 转科
        /// </summary>
        /// <param name="transferDepartmentDto"></param>
        /// <returns></returns>
        [HttpPost]
        public bool TransferDepartment(TransferDepartmentDto transferDepartmentDto)
        {
            return _patientService.TransferDepartment(transferDepartmentDto);
        }
    }
}
